<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
	<head>
		<title>个人中心－交易中的商品</title>
	</head>
	<body>
		<!-- self_info -->
		<div class="grzxbj">
			<div class="selfinfo center">
			<div class="lfnav fl">
				<div class="ddzx">我的商品</div>
				<div class="subddzx">
					<ul>
						<li><a href="${pageContext.request.contextPath}/toMy/sell">出售中的商品</a></li>
						<li><a href="${pageContext.request.contextPath}/toMy/tradingSuccess">已出售的商品</a></li>
						<li><a href="${pageContext.request.contextPath}/toMy/trading" style="color:#ff6700;font-weight:bold;">交易中的商品</a></li>
						<li><a href="${pageContext.request.contextPath}/toMy/shelves">已下架的商品</a></li>
					</ul>
				</div>
				<div class="ddzx">个人中心</div>
				<div class="subddzx">
					<ul>
						<li><a href="${pageContext.request.contextPath}/toMy/my">我的资料</a></li>
						<li><a href="${pageContext.request.contextPath}/toMy/notice">消息通知</a></li>
						<li><a href="${pageContext.request.contextPath}/toMy/rMessage">收到的留言</a></li>
						<li><a href="${pageContext.request.contextPath}/toMy/sMessage">发布的留言</a></li>
						<li><a href="${pageContext.request.contextPath}/toMy/criminalRecords">违规记录</a></li>
						<li><a href="${pageContext.request.contextPath}/toMy/report">举报记录</a></li>
					</ul>
				</div>
			</div>
			<div class="rtcont fr">
				<div class="grzlbt ml40">
					交易中的商品
					<span id="level-tooltip" data-toggle="tooltip" data-placement="right" title="商品交易完成时请确认交易完成，交易失败则可重新上架"></span>
				</div>
				<c:if test="${pagerModel.dates[0] != '' && pagerModel.dates[0] != null}">
					<c:forEach items="${pagerModel.dates}" var="cshtTradingVo">
						<div class="media r-message-media sell-goods-media">
						  <div class="media-left media-middle r-message-media-left">
						    <a href="javascript:void(0)" class="goods-img">
						      <img class="media-object" src="/csht_file/goods_images/${cshtTradingVo.tradingImgpath}" alt="商品图" title="点击看大图">
						    </a>
						  </div>
						  <div class="media-body r-messag-body sell-goods-body trading-success-body">
						  	<h4 class="media-heading">
						  		${cshtTradingVo.tradingTitle}
						  	</h4>
						  	${cshtTradingVo.tradingContent}
						  </div>
						  <div class="sell-goods-right trading-success-right">
						  	<a href="${pageContext.request.contextPath}/goods/goodsDetails/${cshtTradingVo.goodsId}" class="layui-btn layui-btn-primary layui-btn-xs" target="_blank">详细</a>
						  	<a href="javascript:void(0)" class="layui-btn layui-btn-primary layui-btn-xs tradingGoodsToOk">交易完成</a>
						  	<a href="javascript:void(0)" class="layui-btn layui-btn-primary layui-btn-xs tradingGoodsToSell">重新上架</a>
						  	<input type="hidden" value="${cshtTradingVo.tradingId}">
						  </div>
						  <div class="clear"></div>
						  <div class="sell-goods-foot">
						  	<ul>
						  		<li>￥：<b>${cshtTradingVo.tradingPrice}</b></li>
						  		<li>分类：<b>${cshtTradingVo.cshtOneMenu.oneMenuName}/${cshtTradingVo.cshtTwoMenu.twoMenuName}/${cshtTradingVo.cshtThreeMenu.threeMenuName}</b></li>
						  		<li>品牌：<b>${cshtTradingVo.cshtBrand.brandName}</b></li>
						  		<li>学校：<b>${cshtTradingVo.tradingTradeSchool}</b></li>
						  		<li>联系方式：<b>${cshtTradingVo.tradingTradeWay}</b></li>
						  		<li>手续费：<b>${cshtTradingVo.tradingPayMoney}</b></li>
						  		<li>浏览量：<b>${cshtTradingVo.tradingBrowseTime}</b></li>
						  	</ul>
						  </div>
						</div>
					</c:forEach>
					<jsp:include page="../page/page.jsp">
						<jsp:param name="url" value="${pageContext.request.contextPath}/toMy/trading"/>
						<jsp:param name="items" value="${pagerModel.totalSize}"/>
						<jsp:param name="maxPageItems" value="${pagerModel.messagePageSize}"/>
					</jsp:include>
				</c:if>
				
				<c:if test="${pagerModel.dates[0] == '' || pagerModel.dates[0] == null}">
					<div class="null_tishi">
						<img src="${pageContext.request.contextPath}/static/image/null_tishi.gif">
						<p id="autoText">什么都没有…</p>
					</div>
				</c:if>
			</div>
			
			<!-- 浏览商品图模态框 -->
			<div class="modal fade r-messag-modal" id="sell-goods-modal" tabindex="-1" role="dialog">
			  <div class="modal-dialog r-messag-modal-dialog" role="document">
			    <div class="modal-content r-messag-modal-content">
			      <div class="modal-body r-messag-modal-body">
			      </div>
			    </div><!-- /.modal-content -->
			  </div><!-- /.modal-dialog -->
			</div><!-- 浏览商品图模态框 -->
			
			<div class="clear"></div>
			</div>
		</div>
		
		<script type="text/javascript">
			$(document).ready(function(){
				
				//点击交易完成
				$(".tradingGoodsToOk").on("click", function(){
					var tradingId = $(this).siblings("input[type='hidden']").val(); //获取要下架的商品id
					layer.confirm('确定完成该商品的交易？', {
						  btn: ['确定', '取消'] //可以无限个按钮
						}, function(index, layero){
							//ajax访问后台处理
							$.ajax({
								url: "${pageContext.request.contextPath}/toMy/tradingGoodsToOk",
								type: "POST",
								dataType: "JSON",
								data: {
									"tradingId": tradingId
								},
								success: function(data){
									if(true == data.result){
										layer.open({
											  content: '已确认该商品交易完成',
											  title: '提示:',
											  icon: 1,
											  anim: 6,
											  yes: function(index, layero){
												  layer.close(index); //如果设定了yes回调，需进行手工关闭
												  location.reload();
												  }
										});
									}else{
										layer.msg("确认失败，请联系管理员反馈");
									}
								}
							})
						});
				});
				
				//点击重新上架
				$(".tradingGoodsToSell").on("click", function(){
					var tradingId = $(this).siblings("input[type='hidden']").val(); //获取要下架的商品id
					layer.confirm('确定重新上架该商品？', {
						  btn: ['确定', '取消'] //可以无限个按钮
						}, function(index, layero){
							//ajax访问后台处理
							$.ajax({
								url: "${pageContext.request.contextPath}/toMy/tradingGoodsToSell",
								type: "POST",
								dataType: "JSON",
								data: {
									"tradingId": tradingId
								},
								success: function(data){
									if(true == data.result){
										layer.open({
											  content: '该商品已经重新上架',
											  title: '提示:',
											  icon: 1,
											  anim: 6,
											  yes: function(index, layero){
												  layer.close(index); //如果设定了yes回调，需进行手工关闭
												  location.reload();
												  }
										});
									}else{
										layer.msg("上架失败，请联系管理员反馈");
									}
								}
							})
						});
				});
				
				//工具提示
				$('#level-tooltip').tooltip('show');
				
				//点击商品图，浏览大图
				$(".goods-img").on("click", function(){
					var imgSrc = $(this).children("img").attr("src"); //获取图片地址
					$("#sell-goods-modal .modal-body").html("<img src='" + imgSrc + "' alt='商品图'>");
					$("#sell-goods-modal").modal("show");
				});
				
				//点击商品图，浏览大图时，再次点击将隐藏模态框
				$("#sell-goods-modal").on("click", function(){
					$("#sell-goods-modal").modal("hide");
				});
				

				/*跳跳字体动画
				 *  参数详解:
				 *	upTime			上移的时间
				 *	downTime		下落的时间
				 *	beatHeight		上移高度
				 *	isAuth			是否自动
				 *	isRotate		是否旋转
				*/
				$('p#autoText').beatText({isAuth:true,beatHeight:"1.5em",isRotate:false});
				
			})
		</script>
		
		
	</body>
</html>